package syllabus.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import syllabus.dao.PUserMapper;
import syllabus.model.Criteria;
import syllabus.model.PRole;
import syllabus.model.PUser;
import syllabus.service.PUserService;

@Service
public class PUserServiceImpl implements PUserService {
    @Autowired
    private PUserMapper pUserMapper;

    private static final Logger logger = LoggerFactory.getLogger(PUserServiceImpl.class);

    public int countByExample(Criteria example) {
        int count = this.pUserMapper.countByExample(example);
        logger.debug("count: {}", count);
        return count;
    }

    public PUser selectByPrimaryKey(Integer id) {
        return this.pUserMapper.selectByPrimaryKey(id);
    }

    public List<PUser> selectByExample(Criteria example) {
        return this.pUserMapper.selectByExample(example);
    }

    public int deleteByPrimaryKey(Integer id) {
        return this.pUserMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(PUser record) {
        return this.pUserMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(PUser record) {
        return this.pUserMapper.updateByPrimaryKey(record);
    }

    public int deleteByExample(Criteria example) {
        return this.pUserMapper.deleteByExample(example);
    }

    public int updateByExampleSelective(PUser record, Criteria example) {
        return this.pUserMapper.updateByExampleSelective(record, example);
    }

    public int updateByExample(PUser record, Criteria example) {
        return this.pUserMapper.updateByExample(record, example);
    }

    public int insert(PUser record) {
        return this.pUserMapper.insert(record);
    }

    public int insertSelective(PUser record) {
        return this.pUserMapper.insertSelective(record);
    }

	public PUser selectByUser(Criteria c) {
		List<PUser> list = pUserMapper.selectByExample(c);
		
		if (null == list || list.size() != 1) {
			return null;
		}
		PUser user = list.get(0);
		String passwordIn = c.getAsString("password");
		if (passwordIn.equals(user.getPassword())) {
			// 密码正确
			return user;
			// 更新最后登录时间和登录ip
			
		}
		return null;
	}


}